package presenters;

import model.ConnectionManager;
import model.IPresenter;
import views.CreateNewAccountPanel;

public class CreateAccountPresenter extends IPresenter {
	private CreateNewAccountPanel myPanel;

	public CreateAccountPresenter(CreateNewAccountPanel pan) {
		super();
		myPanel = pan;
	}

	public void createAccount(String username, String password,
			String passwordConfirm, String userType) {

		if (checkString(username) && checkString(password)
				&& checkString(passwordConfirm) && checkString(userType)) {
			
			if(password.equals(passwordConfirm)) {
				String table = "";
				/*if("ADMINISTRATOR".equals(userType)) {
					table = "ADMINISTRATOR";
				}			
				else if("EMPLOYEE".equals(userType)) {
					table = "EMPLOYEE";
				}
				else {
					table = "MEMBER";
				}*/
				table = userType;
				
				String table2 = "USER";
				String sql2 = "INSERT INTO " + ConnectionManager.GROUP 
						+ "." + table2 + "(USERNAME, PASSWORD) VALUES('" 
						+ username + "', '" + password + "');";
				int out2 = executeSQLUpdate(sql2);
				
				int out = -1;
				if(userType.equals("ADMINISTRATOR") || userType.equals("EMPLOYEE")) {
					String sql = "INSERT INTO " + ConnectionManager.GROUP 
							+ "." + table + "(USERNAME, PASSWORD) VALUES('" 
							+ username + "', '" + password + "');";
					out = executeSQLUpdate(sql);
				} // close if
				else {
					/*String sql = "INSERT INTO" + ConnectionManager.GROUP
							+ "." + table + "(USERNAME, FIRST_NAME, LAST_NAME, MIDDLE_INIT, ADDRESS, PHONE, EMAIL, PLAN_NAME, CARD_NO)"
							+ " VALUES('"
							+ username + "', 'EMPTY', 'EMPTY', 'E', 'EMPTY', '123456789', 'EMPTY', 'EMPTY', '123456');";
					out = executeSQLUpdate(sql); */
				}
				System.out.println(username + " added to " + table + " at row: " + out);
				System.out.println(username + " added to " + table2 + " at row: " + out2);
			}
		}
	} // close method

} // close class
